package com.atguigu.gmall.activity.api;

import com.atguigu.gmall.activity.model.SeckillGoods;
import com.atguigu.gmall.activity.service.SeckillGoodsService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.AuthContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author: atguigu
 * @create: 2023-03-17 14:20
 */
@RestController
@RequestMapping("/api/activity")
public class SeckillGoodsApiController {

    @Autowired
    private SeckillGoodsService seckillGoodsService;


    /**
     * 查询Redis中当日秒杀商品列表
     *
     * @return
     */
    @GetMapping("/inner/seckill/findAll")
    public Result getSeckillGoodsList() {
        List<SeckillGoods> seckillGoodsList = seckillGoodsService.getSeckillGoodsList();
        return Result.ok(seckillGoodsList);
    }

    /**
     * 查询指定秒杀商品信息
     *
     * @param skuId
     * @return
     */
    @GetMapping("/inner/seckill/getSeckillGoods/{skuId}")
    public Result getSeckillGoods(@PathVariable("skuId") Long skuId) {
        SeckillGoods seckillGoods = seckillGoodsService.getSeckillGoods(skuId);
        return Result.ok(seckillGoods);
    }


    /**
     * 获取当前登录用户秒杀订单确认页面相关数据
     *
     * @return
     */
    @GetMapping("/inner/seckill/auth/trade")
    public Result getSeckillOrderTradeDatas(HttpServletRequest request) {
        //获取当前登录用户ID
        String userId = AuthContextHolder.getUserId(request);
        Map<String, Object> tradeDatas = seckillGoodsService.getSeckillOrderTradeDatas(userId);
        return Result.ok(tradeDatas);
    }
}
